package org.xa3apm.vote.hibernate.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * Entity implementation class for Entity: VotingData
 * 
 */
@Entity
@Table(name = "tVote")
@NamedQueries({ @NamedQuery(name = "VotingData.getByPlace", query = "SELECT V FROM VoteData V WHERE V.settlement = :settlement")

})
public class VoteData implements Serializable {

	@Id
	@GeneratedValue
	@Column(name = "id", nullable = false)
	private Long id;
	@Column(name = "hash", nullable = false)
	private int hash;
	@ManyToOne(targetEntity = Candidate.class)
	private Candidate candidate;
	@Column(name = "settlement")
	private String settlement;
	private static final long serialVersionUID = 1L;

	public VoteData() {
		super();
	}

	public VoteData(int hash, Candidate candidate, String settlement) {
		super();
		this.hash = hash;
		this.candidate = candidate;
		this.settlement = settlement;
	}

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public int getHash() {
		return this.hash;
	}

	public void setHash(int hash) {
		this.hash = hash;
	}

	public String getSettlement() {
		return settlement;
	}

	public void setSettlement(String settlement) {
		this.settlement = settlement;
	}

	public Candidate getCandidate() {
		return candidate;
	}

	public void setCandidate(Candidate candidate) {
		this.candidate = candidate;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((candidate == null) ? 0 : candidate.hashCode());
		result = prime * result + hash;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((settlement == null) ? 0 : settlement.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof VoteData)) {
			return false;
		}
		VoteData other = (VoteData) obj;
		if (candidate == null) {
			if (other.candidate != null) {
				return false;
			}
		} else if (!candidate.equals(other.candidate)) {
			return false;
		}
		if (hash != other.hash) {
			return false;
		}
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		if (settlement == null) {
			if (other.settlement != null) {
				return false;
			}
		} else if (!settlement.equals(other.settlement)) {
			return false;
		}
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "VoteData [id=" + id + ", hash=" + hash + ", candidate="
				+ candidate + ", settlement=" + settlement + "]";
	}

}
